<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"chentianming11.github.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"default"},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":{"enable":true,"onlypost":false,"loadingImg":"/uploads/loading.gif"},"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="mysql数据库是当前应用最为的广泛的数据库，在实际工作中也经常接触到。真正用好mysql也不仅仅是会写sql就行，更重要的是真正理解其内部的工作原理。本文先从宏观角度介绍一些mysql相关的知识点，目的是为了让大家对mysql能有一个大体上的认知，后续再逐一对每个知识点的进行深入解读。">
<meta property="og:type" content="article">
<meta property="og:title" content="mysql进阶知识点，启动项、系统变量、字符集介绍！">
<meta property="og:url" content="https://chentianming11.github.io/posts/2624407690/index.html">
<meta property="og:site_name" content="伍六七">
<meta property="og:description" content="mysql数据库是当前应用最为的广泛的数据库，在实际工作中也经常接触到。真正用好mysql也不仅仅是会写sql就行，更重要的是真正理解其内部的工作原理。本文先从宏观角度介绍一些mysql相关的知识点，目的是为了让大家对mysql能有一个大体上的认知，后续再逐一对每个知识点的进行深入解读。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://chentianming11.github.io/images/mysql/mysql%E5%9F%BA%E6%9C%AC%E6%B5%81%E7%A8%8B.webp">
<meta property="og:image" content="https://chentianming11.github.io/images/mysql/mysql%E5%AD%98%E5%82%A8%E5%BC%95%E6%93%8E.png">
<meta property="article:published_time" content="2020-06-07T09:38:21.000Z">
<meta property="article:modified_time" content="2020-08-06T14:02:43.387Z">
<meta property="article:author" content="陈添明">
<meta property="article:tag" content="mysql">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://chentianming11.github.io/images/mysql/mysql%E5%9F%BA%E6%9C%AC%E6%B5%81%E7%A8%8B.webp">

<link rel="canonical" href="https://chentianming11.github.io/posts/2624407690/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>mysql进阶知识点，启动项、系统变量、字符集介绍！ | 伍六七</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">伍六七</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">一起学Java</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">6</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">3</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">17</span></a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

  <a href="https://github.com/chentianming11" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://chentianming11.github.io/posts/2624407690/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="陈添明">
      <meta itemprop="description" content="一个爱看国漫的程序猿">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="伍六七">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          mysql进阶知识点，启动项、系统变量、字符集介绍！
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-06-07 17:38:21" itemprop="dateCreated datePublished" datetime="2020-06-07T17:38:21+08:00">2020-06-07</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-08-06 22:02:43" itemprop="dateModified" datetime="2020-08-06T22:02:43+08:00">2020-08-06</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/" itemprop="url" rel="index"><span itemprop="name">数据库</span></a>
                </span>
            </span>

          
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/posts/2624407690/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/posts/2624407690/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>7.3k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>18 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>mysql数据库是当前应用最为的广泛的数据库，在实际工作中也经常接触到。真正用好mysql也不仅仅是会写sql就行，更重要的是真正理解其内部的工作原理。本文先从宏观角度介绍一些mysql相关的知识点，目的是为了让大家对mysql能有一个大体上的认知，后续再逐一对每个知识点的进行深入解读。</p>
<a id="more"></a>

<blockquote>
<p>本文主要内容是根据掘金小册《从根儿上理解 MySQL》整理而来。如想详细了解，建议购买掘金小册阅读。</p>
</blockquote>
<h2 id="通信方式"><a href="#通信方式" class="headerlink" title="通信方式"></a>通信方式</h2><p>mysql采用了典型的<strong>客户端/服务器架构(C/S架构)</strong>模式。对于计算机而言，数据库客户端程序和服务器程序分别运在不同的进程中。所以客户端进程向服务器进程发送sql请求并得到返回结果的过程本质上就是<strong>进程间通信</strong>。mysql支持的进程间通信方式包括<code>TCP/IP</code>、<code>命名管道</code>、<code>共享内存</code>、<code>unix域套接字文件</code>。</p>
<ol>
<li><code>TCP/IP</code>: <strong>如果服务端进程和客户端进程运行在不同的主机中，只能通过<code>TCP/IP</code>网络通信协议进行通信</strong>。mysql服务器启动时监听某个端口(默认3306)，等待客户端进程来连接。当然，服务端进程和客户端进程在同一主机中，通过本机回环地址(127.0.0.1)也是可以使用<code>TCP/IP</code>进行通信的。</li>
<li><code>命名管道或共享内存</code>: <strong>如果服务端进程和客户端进程都运行在一台windows主机上，可以通过命名管道或共享内存方式进行通信</strong>。<ol>
<li>使用<code>命名管道</code>来进行进程间通信： 需要在启动服务器程序的命令中加上<code>--enable-named-pipe</code>参数，然后在启动客户端程序的命令中加入<code>--pipe</code>或者<code>--protocol=pipe</code>参数。</li>
<li>使用<code>共享内存</code>来进行进程间通信: 需要在启动服务器程序的命令中加上<code>--shared-memory</code>参数，在成功启动服务器后，共享内存便成为本地客户端程序的默认连接方式，不过我们也可以在启动客户端程序的命令中加入<code>--protocol=memory</code>参数来显式的指定使用共享内存进行通信。</li>
</ol>
</li>
<li><code>Unix域套接字文件</code>: 如果我们的服务器进程和客户端进程都运行在同一台操作系统为类Unix的机器上的话，我们可以使用Unix域套接字文件来进行进程间通信。</li>
</ol>
<p>真实环境中，服务器和客户端基本都是运行在不同主机中的，它们之间采用的通信方式就是<code>TCP/IP</code>。</p>
<h2 id="一条查询sql的基本处理过程"><a href="#一条查询sql的基本处理过程" class="headerlink" title="一条查询sql的基本处理过程"></a>一条查询sql的基本处理过程</h2><p>不论客户端进程和服务器进程是采用哪种方式进行通信，最后实现的效果都是：<strong>客户端向服务器发送一段文本（sql语句），服务器进程处理后再向客户端进程发送一段文本（处理结果）</strong>。下面以查询sql为例，简单说明一下服务器处理客户端请求的大致处理过程。</p>
<p><img data-src="https://chentianming11.github.io/images/mysql/mysql%E5%9F%BA%E6%9C%AC%E6%B5%81%E7%A8%8B.webp" alt="mysql基本处理过程"></p>
<p>从图中我们可以看出，服务器程序处理来自客户端的查询请求大致需要经过三个部分，分别是<code>连接管理</code>、<code>解析与优化</code>、<code>存储引擎</code>。</p>
<h3 id="连接管理"><a href="#连接管理" class="headerlink" title="连接管理"></a>连接管理</h3><p>每当有一个客户端连接到服务器时，服务器都会创建一个线程来专门处理与这个客户端的交互。在客户端程序发起连接的时候，需要携带主机信息、用户名、密码，服务器程序会对客户端程序提供的这些信息进行认证，如果认证失败，服务器程序会拒绝连接。<br>当连接建立后，与该客户端关联的服务器线程会一直等待客户端发送请求，MySQL服务器接收到的请求只是一个文本消息，该文本消息还要经过各种处理才能将最后的处理结果返回客户端。</p>
<h3 id="解析与优化"><a href="#解析与优化" class="headerlink" title="解析与优化"></a>解析与优化</h3><p>到现在为止，MySQL服务器已经获得了文本形式的请求，接着还需要经过<code>查询缓存</code>、<code>语法解析</code>、<code>查询优化</code>等进行处理。</p>
<h4 id="查询缓存"><a href="#查询缓存" class="headerlink" title="查询缓存"></a>查询缓存</h4><p>如果服务器开启了查询缓存，在执行查询的时候会先从查询缓存中获取查询结果。如果命中缓存则直接返回结果，否则接着执行。mysql不推荐使用查询缓存，并且在8.0版本已经移除此功能。真实环境中也不会使用，因此不用详细了解。</p>
<h4 id="语法解析"><a href="#语法解析" class="headerlink" title="语法解析"></a>语法解析</h4><p>这一步主要做的事情是对语句基于<code>SQL语法</code>进行词法和语法分析和语义的解析，将要查询的表、各种查询条件都提取出来放到MySQL服务器内部使用的一些数据结构上来。</p>
<h4 id="查询优化"><a href="#查询优化" class="headerlink" title="查询优化"></a>查询优化</h4><p>因为我们写的MySQL语句执行起来效率可能并不是很高，MySQL的优化程序会对我们的语句做一些优化，如外连接转换为内连接、表达式简化、子查询转为连接等等。优化的结果就是生成一个执行计划，这个执行计划表明了应该使用哪些索引进行查询，表之间的连接顺序等。我们可以使用<code>EXPLAIN</code>语句来查看某个语句的执行计划。</p>
<h3 id="存储引擎"><a href="#存储引擎" class="headerlink" title="存储引擎"></a>存储引擎</h3><p>mysql数据是保存在<code>数据表</code>里面，但表只是逻辑上的概念，数据真正是保存在物理磁盘上的。存储引擎负责的就是物理上数据的保存和提取。为了实现不同的功能，MySQL提供了各式各样的存储引擎，不同存储引擎在物理上的存储结构存在一些差异。但是不同的存储引擎提供了统一的调用接口（也就是存储引擎API）。</p>
<p>mysql支持多种存储引擎，可以通过如下命令查看：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">show</span> <span class="keyword">engines</span> ;</span><br></pre></td></tr></table></figure>

<p><img data-src="https://chentianming11.github.io/images/mysql/mysql%E5%AD%98%E5%82%A8%E5%BC%95%E6%93%8E.png" alt="mysql储存引擎"></p>
<p><strong>虽然支持的存储引擎很多，但是我们需要重点关注InnoDB以及适当了解MyISAM存储引擎即可！</strong></p>
<p>为了管理方便，人们把<code>连接管理</code>、<code>查询缓存</code>、<code>语法解析</code>、<code>查询优化</code>这些并不涉及真实数据存储的功能划分为<code>MySQL server</code>的功能，把真实存取数据的功能划分为<code>存储引擎</code>的功能。</p>
<h2 id="启动选项和系统变量"><a href="#启动选项和系统变量" class="headerlink" title="启动选项和系统变量"></a>启动选项和系统变量</h2><p>mysql程序(包括服务器相关程序和客户端相关程序)在启动的时候可以指定启动参数，来控制程序启动后的行为。这些启动参数可以放在命令行中指定，也可以把它们放在配置文件中指定。</p>
<h3 id="在命令行上使用启动选项"><a href="#在命令行上使用启动选项" class="headerlink" title="在命令行上使用启动选项"></a>在命令行上使用启动选项</h3><p>启动mysql程序的命令行后边指定启动选项的通用格式如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">--启动选项1[=值1] --启动选项2[=值2] ... --启动选项n[=值n]</span><br></pre></td></tr></table></figure>

<p>各个启动选项之间使用空白字符隔开，在每一个启动选项名称前边添加<code>--</code>。对于不需要值的启动选项，比方说<code>skip-networking</code>，它们就不需要指定对应的值。对于需要指定值的启动选项，比如<code>default-storage-engine</code>我们在指定这个设置项的时候需要显式的指定它的值，比方说<code>InnoDB</code>、<code>MyISAM</code>。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysqld --default-storage-engine=MyISAM --skip-networking</span><br></pre></td></tr></table></figure>

<p>比如上面的启动项就表示默认存储引擎为<code>MyISAM</code>，并且禁止使用<code>TCP/IP</code>方式通信。</p>
<p>为了使用的方便，对于一些常用的选项提供了短形式，比如：</p>
<table>
<thead>
<tr>
<th>长形式</th>
<th>短形式</th>
<th>含义</th>
</tr>
</thead>
<tbody><tr>
<td>–host</td>
<td>-h</td>
<td>主机名</td>
</tr>
<tr>
<td>–user</td>
<td>-u</td>
<td>用户名</td>
</tr>
<tr>
<td>–password</td>
<td>-p</td>
<td>密码</td>
</tr>
<tr>
<td>–port</td>
<td>-P</td>
<td>主机名</td>
</tr>
<tr>
<td>–host</td>
<td>-h</td>
<td>端口</td>
</tr>
</tbody></table>
<h3 id="配置文件中使用选项"><a href="#配置文件中使用选项" class="headerlink" title="配置文件中使用选项"></a>配置文件中使用选项</h3><p>相比于使用命令行的方式设置启动选项，mysql更推荐使用配置文件来设置启动选项。我们把需要设置的启动选项都写在这个配置文件中，每次启动服务器的时候都从这个文件里加载相应的启动选项。</p>
<p>MySQL程序在启动时会寻找多个路径下的配置文件，这些路径有的是固定的，有的是可以在命令行指定的。根据操作系统的不同，配置文件的路径也有所不同，并且越后面路径下的配置优先级越好。总之就是多个路径下都可以存在配置文件，并且有个优先级的关系。这里就不展开了。</p>
<h4 id="配置文件的内容"><a href="#配置文件的内容" class="headerlink" title="配置文件的内容"></a>配置文件的内容</h4><p>与在命令行中指定启动选项不同的是，配置文件中的启动选项被划分为若干个组，每个组有一个组名，用中括号<code>[]</code>扩起来，像这样：</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">[server]</span></span><br><span class="line"><span class="attr">(具体的启动选项...)</span></span><br><span class="line"></span><br><span class="line"><span class="attr">[mysqld]</span></span><br><span class="line"><span class="attr">(具体的启动选项...)</span></span><br><span class="line"></span><br><span class="line"><span class="attr">[mysqld_safe]</span></span><br><span class="line"><span class="attr">(具体的启动选项...)</span></span><br><span class="line"></span><br><span class="line"><span class="attr">[client]</span></span><br><span class="line"><span class="attr">(具体的启动选项...)</span></span><br><span class="line"></span><br><span class="line"><span class="attr">[mysql]</span></span><br><span class="line"><span class="attr">(具体的启动选项...)</span></span><br><span class="line"></span><br><span class="line"><span class="attr">[mysqladmin]</span></span><br><span class="line"><span class="attr">(具体的启动选项...)</span></span><br></pre></td></tr></table></figure>

<p>启动mysql程序时，会使用对应的一个或多个组下的启动选项。每个组下边可以定义若干个启动选项，我们以<code>[server]</code>组为例来看一下填写启动选项的形式（其他组中启动选项的形式是一样的）：</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">[server]</span></span><br><span class="line"><span class="attr">option1</span>     <span class="string">#这是option1，该选项不需要选项值</span></span><br><span class="line"><span class="attr">option2</span> = <span class="string">value2      #这是option2，该选项需要选项值</span></span><br></pre></td></tr></table></figure>

<h3 id="系统变量"><a href="#系统变量" class="headerlink" title="系统变量"></a>系统变量</h3><p><strong>mysql系统变量是指能够影响服务器程序运行行为的变量</strong>。比如允许同时连入的客户端数量由系统变量<code>max_connections</code>控制，表的默认存储引擎由系统变量<code>default_storage_engine</code>控制。每个系统变量都有一个默认值，我们可以使用命令行或者配置文件中的选项在启动服务器时改变一些系统变量的值，或者在运行时动态修改(大多数系统变量支持动态修改)。</p>
<h4 id="作用范围"><a href="#作用范围" class="headerlink" title="作用范围"></a>作用范围</h4><p>多个客户端程序可以同时连接到一个服务器程序。对于同一个系统变量，我们有时想让不同的客户端有不同的值，mysql通过<strong>系统变量的作用范围</strong>来解决上述问题。具体来说作用范围分为下面两种：</p>
<ol>
<li><code>GLOBAL</code>：全局变量，影响服务器的整体操作。</li>
<li><code>SESSION</code>：会话变量，影响某个客户端连接的操作。（注：<code>SESSION</code>有个别名叫<code>LOCAL</code>）</li>
</ol>
<p>很显然，通过启动选项设置的系统变量的作用范围都是<code>GLOBAL</code>的，也就是对所有客户端都有效的。通过客户端动态修改系统变量语法如下：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SET</span> [<span class="keyword">GLOBAL</span>|<span class="keyword">SESSION</span>] 系统变量名 = 值;</span><br></pre></td></tr></table></figure>

<p><strong>如果在设置系统变量的语句中省略了作用范围，默认的作用范围就是SESSION。</strong>同理，我们可以使用下列命令查看MySQL服务器程序支持的系统变量以及它们的当前值：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SHOW</span> [<span class="keyword">GLOBAL</span>|<span class="keyword">SESSION</span>] <span class="keyword">VARIABLES</span> [<span class="keyword">LIKE</span> 匹配的模式];</span><br></pre></td></tr></table></figure>

<h3 id="状态变量"><a href="#状态变量" class="headerlink" title="状态变量"></a>状态变量</h3><p><strong>mysql状态变量是指描述服务器运行状态的变量，</strong>比方说<code>Threads_connected</code>表示当前有多少客户端与服务器建立了连接。</p>
<p>由于状态变量是用来显示服务器程序运行状况的，所以<strong>它们的值只能由服务器程序自己来设置（对客户端而言是只读的）</strong>。与系统变量类似，状态变量也有<code>GLOBAL</code>和<code>SESSION</code>两个作用范围的，所以查看状态变量的语句可以这么写：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SHOW</span> [<span class="keyword">GLOBAL</span>|<span class="keyword">SESSION</span>] <span class="keyword">STATUS</span> [<span class="keyword">LIKE</span> 匹配的模式];</span><br></pre></td></tr></table></figure>

<h2 id="mysql支持的字符集和比较规则"><a href="#mysql支持的字符集和比较规则" class="headerlink" title="mysql支持的字符集和比较规则"></a>mysql支持的字符集和比较规则</h2><p>在计算机中，数据最终都是以二进制的形式保存的。因此，如果我们要保存字符串，首先就先得确定字符串中的每个字符对应的二进制数据是什么，然后再将这些二进制数据保存到计算机中。将一个字符映射成一个二进制数据的过程也叫做<code>编码</code>，将一个二进制数据映射到一个字符的过程叫做<code>解码</code>。</p>
<p>使用字符集可以解决数据存储的问题，但是无法完全解决字符之间相互比较的问题。简单场景下，我们可以直接通过比较字符的二进制数据来判断大小，这种方式其实就是<code>二进制比较规则</code>。而有些场景下，<code>二进制比较规则</code>并不适用，比如忽略大小写的时候。因此<strong>为了应对不同的场景，同一种字符集可以有多种比较规则</strong>。</p>
<h3 id="字符集"><a href="#字符集" class="headerlink" title="字符集"></a>字符集</h3><p>mysql中支持很多种字符集，可以通过以下语句查看：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SHOW</span> <span class="keyword">CHARSET</span> [<span class="keyword">LIKE</span> 匹配的模式];</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">mysql&gt;</span><span class="bash"> SHOW CHARSET;</span></span><br><span class="line">+----------+---------------------------------+---------------------+--------+</span><br><span class="line">| Charset  | Description                     | Default collation   | Maxlen |</span><br><span class="line">+----------+---------------------------------+---------------------+--------+</span><br><span class="line">| utf8     | UTF-8 Unicode                   | utf8_general_ci     |      3 |</span><br><span class="line">| ucs2     | UCS-2 Unicode                   | ucs2_general_ci     |      2 |</span><br><span class="line">...</span><br><span class="line">| latin7   | ISO 8859-13 Baltic              | latin7_general_ci   |      1 |</span><br><span class="line">| utf8mb4  | UTF-8 Unicode                   | utf8mb4_general_ci  |      4 |</span><br><span class="line">| utf16    | UTF-16 Unicode                  | utf16_general_ci    |      4 |</span><br><span class="line">| utf16le  | UTF-16LE Unicode                | utf16le_general_ci  |      4 |</span><br><span class="line">...</span><br><span class="line">+----------+---------------------------------+---------------------+--------+</span><br><span class="line">41 rows in set (0.01 sec)</span><br></pre></td></tr></table></figure>

<ol>
<li><code>Charset</code>: 字符集名称</li>
<li><code>Description</code>: 字符集描述</li>
<li><code>Default collation</code>: 默认的比较规则</li>
<li><code>Maxlen</code>: 一个字符最大占用的字节数。对于采用<code>变长编码方式</code>的字符集而言，一个字符占用的字节数不是固定的。比如在<code>GB2312字符集</code>中，一个字母只占用1个字节，而一个汉字占用了2个字节。</li>
</ol>
<p>在mysql中，<code>utf8</code>和<code>utf8mb4</code>的区别就在于1个字符占用的最大字节数不同。<code>utf8</code>一个字符占用1-3个字节，而<code>utf8mb4</code>一个字符占用1-4个字节。实际上，mysql的<code>utf8</code>是<code>utf8mb3</code>的别名。如果需要保存一些占用4个字节的特殊字符(比如emoji表情)，建议使用<code>utf8mb4</code>字符集。</p>
<h3 id="比较规则"><a href="#比较规则" class="headerlink" title="比较规则"></a>比较规则</h3><p>可以通过以下语句查看mysql中支持的比较规则：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SHOW</span> <span class="keyword">COLLATION</span> [<span class="keyword">LIKE</span> 匹配的模式];</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">mysql&gt;</span><span class="bash"> SHOW COLLATION LIKE <span class="string">'utf8\_%'</span>;</span></span><br><span class="line">+--------------------------+---------+-----+---------+----------+---------+</span><br><span class="line">| Collation                | Charset | Id  | Default | Compiled | Sortlen |</span><br><span class="line">+--------------------------+---------+-----+---------+----------+---------+</span><br><span class="line">| utf8_general_ci          | utf8    |  33 | Yes     | Yes      |       1 |</span><br><span class="line">| utf8_bin                 | utf8    |  83 |         | Yes      |       1 |</span><br><span class="line">...</span><br><span class="line">+--------------------------+---------+-----+---------+----------+---------+</span><br><span class="line">27 rows in set (0.00 sec)</span><br></pre></td></tr></table></figure>

<ol>
<li><code>Collation</code>: 比较规则名称，基本符合<code>字符集名称_语言_后缀</code>模式。第一部分<code>字符集名称</code>就是与其关联的字符集的名称开头，第二部分表示该比较规则作用的语言，比如<code>utf8_spanish_ci</code>是以西班牙语的规则比较，<code>utf8_general_ci</code>是一种通用的比较规则。第三部分后缀主要用来表示要不要区分大小写和重音之类的。</li>
<li><code>Charset</code>: 关联的字符集的名称。</li>
<li><code>Default</code>: yes表示是字符集默认的比较规则。</li>
</ol>
<table>
<thead>
<tr>
<th>后缀</th>
<th>英文释义</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>_ai</td>
<td>accent insensitive</td>
<td>不区分重音</td>
</tr>
<tr>
<td>_as</td>
<td>accent</td>
<td>sensitive</td>
</tr>
<tr>
<td>_ci</td>
<td>case insensitive</td>
<td>不区分大小写</td>
</tr>
<tr>
<td>_cs</td>
<td>case sensitive</td>
<td>区分大小写</td>
</tr>
<tr>
<td>_bin</td>
<td>binary</td>
<td>以二进制方式比较</td>
</tr>
</tbody></table>
<h3 id="字符集和比较规则作用域级别"><a href="#字符集和比较规则作用域级别" class="headerlink" title="字符集和比较规则作用域级别"></a>字符集和比较规则作用域级别</h3><p>mysql中字符集和比较规则有4种作用域级别：</p>
<ol>
<li>服务器级别</li>
<li>数据库级别</li>
<li>表级别</li>
<li>列级别</li>
</ol>
<p>实际上，<strong>字符集和比较较规则最后肯定是作用在<code>列级别</code>字段上的</strong>。可以简单的认为，如果<code>列级别</code>没有指定字符集和比较较规则，就使用<code>表级别</code>的；如果<code>表级别</code>没有指定字符集和比较较规则，就使用<code>数据库级别</code>的；以此类推。</p>
<h4 id="服务器级别"><a href="#服务器级别" class="headerlink" title="服务器级别"></a>服务器级别</h4><p>MySQL提供了两个系统变量来表示服务器级别的字符集和比较规则：</p>
<ul>
<li><code>character_set_server</code>: 服务器级别的字符集</li>
<li><code>collation_server</code>: 服务器级别的比较规则</li>
</ul>
<p>服务器级别默认的字符集是<code>utf8</code>，默认的比较规则是<code>utf8_general_ci</code>。</p>
<h4 id="数据库级别"><a href="#数据库级别" class="headerlink" title="数据库级别"></a>数据库级别</h4><p>我们在创建和修改数据库的时候可以指定该数据库的字符集和比较规则，具体语法如下：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">DATABASE</span> 数据库名</span><br><span class="line">     <span class="built_in">CHARACTER</span> <span class="keyword">SET</span> 字符集名称</span><br><span class="line">     <span class="keyword">COLLATE</span> 比较规则名称;</span><br><span class="line"></span><br><span class="line"><span class="keyword">ALTER</span> <span class="keyword">DATABASE</span> 数据库名</span><br><span class="line">    <span class="built_in">CHARACTER</span> <span class="keyword">SET</span> 字符集名称</span><br><span class="line">    <span class="keyword">COLLATE</span> 比较规则名称;</span><br></pre></td></tr></table></figure>

<p>比如：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">mysql&gt; CREATE DATABASE charset_demo_db</span><br><span class="line">    -&gt; CHARACTER SET gb2312</span><br><span class="line">    -&gt; COLLATE gb2312_chinese_ci;</span><br><span class="line">Query OK, 1 row affected (0.01 sec)</span><br></pre></td></tr></table></figure>

<p>如果想查看当前数据库使用的字符集和比较规则，可以查看下面两个系统变量的值:</p>
<ul>
<li><code>character_set_database</code>: 当前数据库的字符集</li>
<li><code>collation_database</code>: 当前数据库的比较规则</li>
</ul>
<h4 id="表级别"><a href="#表级别" class="headerlink" title="表级别"></a>表级别</h4><p>我们可以在创建和修改表的时候指定表的字符集和比较规则，语法如下：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> 表名</span><br><span class="line">    (列的信息)</span><br><span class="line">    <span class="built_in">CHARACTER</span> <span class="keyword">SET</span> 字符集名称</span><br><span class="line">    <span class="keyword">COLLATE</span> 比较规则名称</span><br><span class="line"></span><br><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> 表名</span><br><span class="line">    <span class="built_in">CHARACTER</span> <span class="keyword">SET</span> 字符集名称</span><br><span class="line">    <span class="keyword">COLLATE</span> 比较规则名称</span><br></pre></td></tr></table></figure>

<p>比如：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">mysql&gt; CREATE TABLE t(</span><br><span class="line">    -&gt;     col VARCHAR(10)</span><br><span class="line">    -&gt; ) CHARACTER SET utf8 COLLATE utf8_general_ci;</span><br><span class="line">Query OK, 0 rows affected (0.03 sec)</span><br></pre></td></tr></table></figure>

<h4 id="列级别"><a href="#列级别" class="headerlink" title="列级别"></a>列级别</h4><p>需要注意的是，对于存储字符串的列，<strong>同一个表中的不同的列也可以有不同的字符集和比较规则</strong>。我们在创建和修改列定义的时候可以指定该列的字符集和比较规则，语法如下：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> 表名(</span><br><span class="line">    列名 字符串类型 <span class="built_in">CHARACTER</span> <span class="keyword">SET</span> 字符集名称 <span class="keyword">COLLATE</span> 比较规则名称,</span><br><span class="line">    其他列...</span><br><span class="line">);</span><br><span class="line"></span><br><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> 表名 <span class="keyword">MODIFY</span> 列名 字符串类型 <span class="built_in">CHARACTER</span> <span class="keyword">SET</span> 字符集名称 <span class="keyword">COLLATE</span> 比较规则名称;</span><br></pre></td></tr></table></figure>

<p>比如我们修改一下表t中列col的字符集和比较规则可以这么写：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">mysql&gt; ALTER TABLE t MODIFY col VARCHAR(10) CHARACTER SET gbk COLLATE gbk_chinese_ci;</span><br><span class="line">Query OK, 0 rows affected (0.04 sec)</span><br><span class="line">Records: 0  Duplicates: 0  Warnings: 0</span><br></pre></td></tr></table></figure>

<p>还需要注意的一点是：<strong>由于字符集和比较规则是相互联系的，如果我们只修改了字符集和比较规则，都可能引起关联的字符集和比较规则发生变化</strong>。</p>
<blockquote>
<p>原创不易，觉得文章写得不错的小伙伴，点个赞👍 鼓励一下吧~</p>
</blockquote>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/mysql/" rel="tag"># mysql</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/posts/2363983740/" rel="prev" title="数据量大了一定要分表，分库分表组件Sharding-JDBC入门与项目实战">
      <i class="fa fa-chevron-left"></i> 数据量大了一定要分表，分库分表组件Sharding-JDBC入门与项目实战
    </a></div>
      <div class="post-nav-item">
    <a href="/posts/786374041/" rel="next" title="mysql存储引擎InnoDB详解，从底层看清InnoDB数据结构">
      mysql存储引擎InnoDB详解，从底层看清InnoDB数据结构 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#通信方式"><span class="nav-number">1.</span> <span class="nav-text">通信方式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#一条查询sql的基本处理过程"><span class="nav-number">2.</span> <span class="nav-text">一条查询sql的基本处理过程</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#连接管理"><span class="nav-number">2.1.</span> <span class="nav-text">连接管理</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#解析与优化"><span class="nav-number">2.2.</span> <span class="nav-text">解析与优化</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#查询缓存"><span class="nav-number">2.2.1.</span> <span class="nav-text">查询缓存</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#语法解析"><span class="nav-number">2.2.2.</span> <span class="nav-text">语法解析</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#查询优化"><span class="nav-number">2.2.3.</span> <span class="nav-text">查询优化</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#存储引擎"><span class="nav-number">2.3.</span> <span class="nav-text">存储引擎</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#启动选项和系统变量"><span class="nav-number">3.</span> <span class="nav-text">启动选项和系统变量</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#在命令行上使用启动选项"><span class="nav-number">3.1.</span> <span class="nav-text">在命令行上使用启动选项</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#配置文件中使用选项"><span class="nav-number">3.2.</span> <span class="nav-text">配置文件中使用选项</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#配置文件的内容"><span class="nav-number">3.2.1.</span> <span class="nav-text">配置文件的内容</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#系统变量"><span class="nav-number">3.3.</span> <span class="nav-text">系统变量</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#作用范围"><span class="nav-number">3.3.1.</span> <span class="nav-text">作用范围</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#状态变量"><span class="nav-number">3.4.</span> <span class="nav-text">状态变量</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#mysql支持的字符集和比较规则"><span class="nav-number">4.</span> <span class="nav-text">mysql支持的字符集和比较规则</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#字符集"><span class="nav-number">4.1.</span> <span class="nav-text">字符集</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#比较规则"><span class="nav-number">4.2.</span> <span class="nav-text">比较规则</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#字符集和比较规则作用域级别"><span class="nav-number">4.3.</span> <span class="nav-text">字符集和比较规则作用域级别</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#服务器级别"><span class="nav-number">4.3.1.</span> <span class="nav-text">服务器级别</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#数据库级别"><span class="nav-number">4.3.2.</span> <span class="nav-text">数据库级别</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#表级别"><span class="nav-number">4.3.3.</span> <span class="nav-text">表级别</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#列级别"><span class="nav-number">4.3.4.</span> <span class="nav-text">列级别</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="陈添明"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">陈添明</p>
  <div class="site-description" itemprop="description">一个爱看国漫的程序猿</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">17</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">3</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">6</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">陈添明</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="站点总字数">156k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">6:30</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script size="300" alpha="0.6" zIndex="-1" src="//cdn.jsdelivr.net/gh/theme-next/theme-next-canvas-ribbon@1/canvas-ribbon.js"></script>
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/theme-next/theme-next-pjax@0/pjax.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/lozad@1/dist/lozad.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>

  <script>
var pjax = new Pjax({
  selectors: [
    'head title',
    '#page-configurations',
    '.content-wrap',
    '.post-toc-wrap',
    '.languages',
    '#pjax'
  ],
  switches: {
    '.post-toc-wrap': Pjax.switches.innerHTML
  },
  analytics: false,
  cacheBust: false,
  scrollTo : !CONFIG.bookmark.enable
});

window.addEventListener('pjax:success', () => {
  document.querySelectorAll('script[data-pjax], script#page-configurations, #pjax script').forEach(element => {
    var code = element.text || element.textContent || element.innerHTML || '';
    var parent = element.parentNode;
    parent.removeChild(element);
    var script = document.createElement('script');
    if (element.id) {
      script.id = element.id;
    }
    if (element.className) {
      script.className = element.className;
    }
    if (element.type) {
      script.type = element.type;
    }
    if (element.src) {
      script.src = element.src;
      // Force synchronous loading of peripheral JS.
      script.async = false;
    }
    if (element.dataset.pjax !== undefined) {
      script.dataset.pjax = '';
    }
    if (code !== '') {
      script.appendChild(document.createTextNode(code));
    }
    parent.appendChild(script);
  });
  NexT.boot.refresh();
  // Define Motion Sequence & Bootstrap Motion.
  if (CONFIG.motion.enable) {
    NexT.motion.integrator
      .init()
      .add(NexT.motion.middleWares.subMenu)
      .add(NexT.motion.middleWares.postList)
      .bootstrap();
  }
  NexT.utils.updateSidebarPosition();
});
</script>




  




  
<script src="/js/local-search.js"></script>













    <div id="pjax">
  

  
  <script src="//cdn.jsdelivr.net/npm/quicklink@1/dist/quicklink.umd.js"></script>
  <script>
      window.addEventListener('load', () => {
      quicklink({
        timeout : 3000,
        priority: true,
        ignores : [uri => uri.includes('#'),uri => uri === 'https://chentianming11.github.io/posts/2624407690/',]
      });
      });
  </script>


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : true,
      appId      : 'SoPxUkme2aynTULaNuIc5TIq-gzGzoHsz',
      appKey     : '4TDP7SMCbgDKTOGGUtpIeA0H',
      placeholder: "留下点足迹吧~",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : false,
      lang       : '' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

    </div>
</body>
</html>
